package handlers

import (
	"github.com/gin-gonic/gin"
	"repo-master1/models"
	"strconv"
)

func AddBox(c *gin.Context) {
	box_name := c.PostForm("box_name")
	box_num, _ := strconv.Atoi(c.PostForm("box_num"))
	if box_name == "" || box_num == 0 {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "数据不能为空",
		})
		return
	}

	box := models.Box{
		BoxName: box_name,
		BoxNum:  box_num,
	}

	err := models.DB.Create(&box).Error

	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
